import demoracer.Race
import demoracer.Track
import demoracer.Pilot
import java.text.SimpleDateFormat

class BootStrap {

     def init = { servletContext ->

       SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")

       Race race = new Race(name: 'Lemans 24H')
       Track track = new Track(name: 'Lemans')
       race.track = track;

       Race raceRadiator09 = new Race(name: 'Radiator Trophy 2009')
       Race raceRadiator10 = new Race(name: 'Radiator Trophy 2010')
       Track trackRadiator = new Track(name: 'Radiator Springs')
       raceRadiator09.track = trackRadiator
       raceRadiator10.track = trackRadiator

       track.save()
       race.save()
       trackRadiator.save()
       raceRadiator09.save()
       raceRadiator10.save()


       Pilot pilot = new Pilot(name: 'Danica Patrick', birthDate:sdf.parse("25/03/1982"))
       pilot.addToRaces(race)
       pilot.save()

       Pilot pilot2 = new Pilot(name: 'Bolt McQueen', birthDate:sdf.parse("25/06/2006"))
       pilot2.addToRaces(race)
       pilot2.addToRaces(raceRadiator09)
       pilot2.addToRaces(raceRadiator10)
       pilot2.save()

       for(def i=1 ; i < 35 ; i++){
          Pilot pilotAn = new Pilot(name: 'Anonimous ' +i, birthDate: new Date())
          pilotAn.save()

       }



     }
     def destroy = {
     }
} 